//Wrapper for EE::World
#pragma once
#include "stdafx.h"

namespace EsenthelNet
{
	///<summary>World Mode</summary>
	public enum class WorldMode {
		///<summary>Streamed world (loads and unloads areas depending on their distance to center of action)</summary>
		WORLD_STREAM,
		///<summary>Full world (at start loads full world, may consume lots of memory)</summary>
		WORLD_FULL  ,  
	};

	TEMPLATE2
	public ref class MemxList : public System::Collections::Generic::List<TYPE0> {
	internal:
		Game::ObjMemx<TYPE1> container;

	public:



	};

	///<summary>World Manager</summary>
	public ref class WorldManager {
	public:
		~WorldManager() { Game::World.del(); }

		///<summary>This specifies which should be updated first - objects or the physics, default=true (setting it to false may occur in lack of synchronization between the character mesh and its controller when using Physics.draw, false is required for synchronization of character physical clothing)</summary>
		Prop(bool, UpdateObjectsAfterPhys, EE::Game::World.update_objects_after_physics)

		///<summary>Initialize the world, 'mode'=WORLD_MODE, 'secure'=securing keys for save games</summary>
		EsenthelNet::WorldManager^ Init() { Game::World.init(); return this; }
		///<summary>Initialize the world, 'mode'=WORLD_MODE, 'secure'=securing keys for save games</summary>
		EsenthelNet::WorldManager^ Init(EsenthelNet::WorldMode mode) { Game::World.init((Game::WORLD_MODE)mode); return this; }

		EsenthelNet::WorldManager^ SetObjType(System::Collections::Generic::List<EsenthelNet::Obj^>^ container, int objType) {
			////Get unmanaged container for objects
			//EE::Game::ObjMemx<EE::Game::Obj> cont;
			//Game::World.setObjType(cont, objType);

			////Create the managed container
			//container = gcnew System::Collections::Generic::List<EsenthelNet::Obj^>();

			////Add the unmanaged objects to the managed container
			//int elms = cont.elms();																					
			//for(int i = 0; i < elms; i++) {		
			//	container->Add(gcnew EsenthelNet::Obj(&cont.validElm(i)));																	
			//}

			return this;
		}

		//ToDo: Extended List, which uses a EE::Game::ObjMemx instance
		EsenthelNet::WorldManager^ SetObjType([System::Runtime::InteropServices::OutAttribute] System::Collections::Generic::List<EsenthelNet::Chr^>^% container, int objType) {
			//Get unmanaged container for objects
			EE::Game::ObjMemx<EE::Game::Chr> cont;
			Game::World.setObjType(cont, objType);

			//Create the managed container
			container = gcnew System::Collections::Generic::List<EsenthelNet::Chr^>();

			//Add the unmanaged objects to the managed container
			int elms = cont.elms();																					
			for(int i = 0; i < elms; i++) {		
				container->Add(gcnew EsenthelNet::Chr(&cont.validElm(i)));																	
			}

			return this;
		}

		///<summary>New from 'world_dir' directory, false on fail</summary>
		bool NewTry(System::String^ worldDir) { return Game::World.NewTry(ToEEStr(worldDir)); }
		///<summary>New  from 'world_dir' directory, Exit  on fail</summary>
		EsenthelNet::WorldManager^ New(System::String^ worldDir) { Game::World.New(ToEEStr(worldDir)); return this; }


		///<summary>Update, 'pos'= center of action</summary>
		void Update(EsenthelNet::Vec^ pos) { Game::World.update(*pos->vec); }

		void Draw() { Game::World.draw(); }
	};
}
